<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:h="http://java.sun.com/jsf/html" 
    xmlns:f="http://java.sun.com/jsf/core">
    
   	<link rel="stylesheet" type="text/css" href="resources/css/jquery.datetimepicker.css"></link>
	<script src="resources/jquery.js"></script>
	<script src="resources/jquery.datetimepicker.js"></script>
	
	<script>
  $(function() {
    $(".datepicker").datetimepicker({
	    minDate: 0,
	    step: 15,
	    theme: 'dark',
	    minTime: '10:00'
    });   
  }); 
  
  </script>
<h:head>
<f:loadBundle basename="resources.application" var="msg"/>
    <title><h:outputText value="Cinema Admin website" /></title>
    <h:outputStylesheet library="css" name="admin.css"  />
</h:head>
<f:event listener="#{adminController.checkLogin}" type="preRenderView" />
<h:body>
<div class="centerDiv">
<h:form>
<h:commandButton class="selectBtn1" value="Films" action="#{adminController.showFilms}"/>
<h:commandButton class="selectBtn2" value="Rooms" action="#{adminController.showRooms}"/>
<h:commandButton class="selectBtn3" value="Showings" action="#{adminController.showShowings}"/>
</h:form>
<h:form rendered="#{adminController.showFilms}">
<h:dataTable name="movieTable" value="#{adminController.movies}" var="movie"
   styleClass="cinemaTable"
   headerClass="cinemaTableHeader"
   rowClasses="cinemaTableOddRow,cinemaTableEvenRow">
   <h:column>    				
      <f:facet name="header">Title</f:facet>    				    				
      <h:inputText id="newTitle" label="Title" value="#{movie.title}"
         size="10" rendered="#{movie.canEdit}">
         <f:validateLength minimum="2" />
      </h:inputText>
      <h:outputText value="#{movie.title}"
         rendered="#{not movie.canEdit}" />
   </h:column>
   <h:column>
      <f:facet name="header">Length</f:facet>
      <h:inputText id="newLength" label="Length" value="#{movie.length}"
         size="10" rendered="#{movie.canEdit}">
         <f:validateLength minimum="2" />
      </h:inputText>
      <h:outputText value="#{movie.length}"
         rendered="#{not movie.canEdit}" />
   </h:column>
   <h:column>
      <f:facet name="header">Description</f:facet>
      <h:inputText id="newDesc" label="Description" value="#{movie.description}"
         size="10" rendered="#{movie.canEdit}">
         <f:validateLength minimum="2" />
      </h:inputText>
      <h:outputText value="#{movie.description}"
         rendered="#{not movie.canEdit}" />
   </h:column>
   <h:column>
      <f:facet name="header">Edit</f:facet>
         <h:commandButton class="adminButton" value="Edit" 
            action="#{adminController.editMovie}" 
            rendered="#{not movie.canEdit}">        
            <f:setPropertyActionListener 
               target="#{adminController.movie}" value="#{movie}" />
         </h:commandButton>
         <h:commandButton class="adminButton" value="Save" 
            action="#{adminController.saveMovie}" 
            rendered="#{movie.canEdit}">  
            <f:setPropertyActionListener 
               target="#{adminController.movie}" value="#{movie}" />      
         </h:commandButton>
   </h:column>
   <h:column>
      <f:facet name="header">Delete</f:facet>
         <h:commandButton class="adminButton" value="Delete" 
            action="#{adminController.deleteMovie}">                
            <f:setPropertyActionListener 
               target="#{adminController.movie}" value="#{movie}" />
         </h:commandButton>
   </h:column>
</h:dataTable>
<h:message for="newTitle" style="color:red" />
<h:message for="newLength" style="color:red" />
<h:message for="newDesc" style="color:red" /> 
</h:form>
<h:form rendered="#{adminController.showFilms}">
      <h3>Add Movie</h3>
      <table>
      <tr>
            <td>Title:</td>
            <td><h:inputText id="titleInput" label="Title" class="inputText"
            	size="20" value="#{adminController.title}">
            	<f:validateLength minimum="2" />
      			</h:inputText>
      		</td>
      </tr>
      <tr>
            <td>Length:</td>
            <td><h:inputText id="lengthInput" label="Length" class="inputText"
            	size="10" value="#{adminController.length}" >
            	<f:validateLength minimum="2" />
      			</h:inputText>
      		</td>	
      </tr>
      <tr>
            <td>Description:</td>
            <td><h:inputText id="descInput" label="Description" class="inputText"
            	size="40" value="#{adminController.description}" >
            	<f:validateLength minimum="2" />
      			</h:inputText>
      		</td>
      </tr>
      <tr>
            <td> </td>
            <td><h:commandButton value="Add Movie" class="adminButton" 
               action="#{adminController.addMovie}" /></td>
      </tr>
      </table>
</h:form>
<h:form rendered="#{adminController.showRooms}">
<h:dataTable value="#{roomController.rooms}" var="room"
   styleClass="cinemaTable"
   headerClass="cinemaTableHeader"
   rowClasses="cinemaTableOddRow,cinemaTableEvenRow">
   <h:column>    				
      <f:facet name="header">Name</f:facet>    				    				
      <h:inputText id="newName" label="Title" value="#{room.name}"
         size="10" rendered="#{room.canEdit}">
         <f:validateLength minimum="2" />
      </h:inputText>
      <h:outputText value="#{room.name}"
         rendered="#{not room.canEdit}" />
   </h:column>
   <h:column>
      <f:facet name="header">Edit</f:facet>
         <h:commandButton class="adminButton" value="Edit" 
            action="#{roomController.editRoom}" 
            rendered="#{not room.canEdit}">        
            <f:setPropertyActionListener 
               target="#{roomController.room}" value="#{room}" />
         </h:commandButton>
         <h:commandButton class="adminButton" value="Save" 
            action="#{roomController.saveRoom}" 
            rendered="#{room.canEdit}">  
            <f:setPropertyActionListener 
               target="#{roomController.room}" value="#{room}" />      
         </h:commandButton>
   </h:column>
   <h:column>
      <f:facet name="header">Delete</f:facet>
         <h:commandButton class="adminButton" value="Delete" 
            action="#{roomController.deleteRoom}">                
            <f:setPropertyActionListener 
               target="#{roomController.room}" value="#{room}" />
         </h:commandButton>
   </h:column>
</h:dataTable>
<h:message for="newName" style="color:red" />
</h:form>
<h:form rendered="#{adminController.showRooms}">

      <h3>Add Room</h3>
      <table>
      <tr>
            <td>Name:</td>
            <td><h:inputText id="nameInput" label="Name" class="inputText"
            	size="20" value="#{roomController.name}">
            	<f:validateLength minimum="2" />
      			</h:inputText>
      		</td>
      </tr>
      <tr>
            <td> </td>
            <td><h:commandButton value="Add Room" class="adminButton" 
               action="#{roomController.addRoom}" /></td>
      </tr>
      </table>
</h:form>
<h:form rendered="#{adminController.showShowings}">
<h:dataTable value="#{adminController.timeTables}" var="timeTable"
   styleClass="cinemaTable"
   headerClass="cinemaTableHeader"
   rowClasses="cinemaTableOddRow,cinemaTableEvenRow">
   <h:column>    				
      <f:facet name="header">Movie</f:facet>    				    				
      <h:selectOneMenu value="#{adminController.title}" rendered="#{timeTable.canEdit}" class="inputText">
    	  <f:selectItems value="#{adminController.movies}" var="movie" itemLabel="#{movie.title}"/>
	  </h:selectOneMenu> 
      <h:outputText value="#{timeTable.movie.title}"
         rendered="#{not timeTable.canEdit}" />
   </h:column>
   <h:column>
      <f:facet name="header">Start time</f:facet>
      <h:inputText class="datepicker" value="#{adminController.startTime}" rendered="#{timeTable.canEdit}">
      	<f:convertDateTime
         pattern="yyyy/MM/dd HH:mm" />
      </h:inputText>
      <h:outputText value="#{timeTable.startTime}"
         rendered="#{not timeTable.canEdit}" />
   </h:column>
   <h:column>
      <f:facet name="header">Room</f:facet>
      <h:selectOneMenu value="#{roomController.name}" rendered="#{timeTable.canEdit}" class="inputText">
    	  <f:selectItems value="#{roomController.rooms}" var="room" itemLabel="#{room.name}"/>
	  </h:selectOneMenu>
      <h:outputText value="#{timeTable.room.name}"
         rendered="#{not timeTable.canEdit}" />
   </h:column>
   <h:column>
      <f:facet name="header">Edit</f:facet>
         <h:commandButton class="adminButton" value="Edit" 
            action="#{adminController.editTimeTable}" 
            rendered="#{not timeTable.canEdit}">        
            <f:setPropertyActionListener 
               target="#{adminController.timeTable}" value="#{timeTable}" />
         </h:commandButton>
         <h:commandButton class="adminButton" value="Save" 
            action="#{adminController.saveTimeTable}" 
            rendered="#{timeTable.canEdit}">  
            <f:setPropertyActionListener 
               target="#{adminController.timeTable}" value="#{timeTable}" />      
         </h:commandButton>
   </h:column>
   <h:column>
      <f:facet name="header">Delete</f:facet>
         <h:commandButton class="adminButton" value="Delete" 
            action="#{adminController.deleteTimeTable}">                
            <f:setPropertyActionListener 
               target="#{adminController.timeTable}" value="#{timeTable}" />
         </h:commandButton>
   </h:column>
</h:dataTable>
</h:form>
<h:form rendered="#{adminController.showShowings}">
      <h3>Add Showing</h3>
      <table>
      <tr>
            <td>Movie:</td>
            <td>
            	<h:selectOneMenu value="#{adminController.movieId}" class="adminButton"> 
    	  			<f:selectItems value="#{adminController.movies}" var="movie"
    	  				itemValue="#{movie.mId}" itemLabel="#{movie.title}"/> 
	  			</h:selectOneMenu>
      		</td>
      </tr>
      <tr>
            <td>Start Time:</td>
            <td>
            	<h:inputText class="datepicker" value="#{adminController.startTime}" >
            		<f:validateLength minimum="2" />
            		<f:convertDateTime
         			pattern="yyyy/MM/dd HH:mm" />
         		</h:inputText>
      		</td>	
      </tr>
      <tr>
            <td>Room:</td>
            <td>
            	<h:selectOneMenu value="#{adminController.roomId}" class="adminButton">
    	  			<f:selectItems value="#{adminController.rooms}" var="room" 
    	  			itemValue="#{room.roomId}" itemLabel="#{room.name}"/>
	  			</h:selectOneMenu>
      		</td>
      </tr>
      <tr>
      		<td> </td>
            <td>
            	<h:commandButton value="Add Showing" class="adminButton" 
               action="#{adminController.addTimeTable}" />
            </td>
      </tr>
      </table>
</h:form>
<h:form>
<h:commandButton class="adminButton" action="#{adminController.logOut}" value="Log out" />
</h:form>
</div>
<h:messages />
</h:body>
</html>
